export default {
  namespaced: true,
  state () {
    return {
      token: window.localStorage.getItem('token'),
      refreshToken: window.localStorage.getItem('refreshToken'),
      cancelTokenArr: []
    }
  },
  mutations: {
    pushCancelFn (state, obj) {
      state.cancelTokenArr.push(obj.cancelToken)
    },
    clearBeforeHttp (state) {
      state.cancelTokenArr.forEach((item) => {
        console.log(item, '======执行了')
        // 每一个取消函数进行执行 就取消了之前的请求
        item()
      })
    },
    setToken (state, token) {
      state.token = token
      // 最新的token保存到本地
      window.localStorage.setItem('token', token)
    },
    setRefreshToken (state, refreshToken) {
      state.refreshToken = refreshToken
      // 最新的token保存到本地
      window.localStorage.setItem('refreshToken', refreshToken)
    }
  },
  getters: {},
  actions: {}
}
